﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ToolBoxPro;
using LinqObj;

public partial class resetpassword : System.Web.UI.Page
{
    ToolboxDataContext tdc = new ToolboxDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSubmit_Click(object sender, ImageClickEventArgs e)
    {
        var user = from u in tdc.Toolbox_Users
                   where u.user_name == Request.QueryString["username"].ToString() && u.randomstring == Request.QueryString["randomstring"].ToString()
                   select u;
        if (user.Count() > 0)
        {
            user.Single().password = txtpassword.Text;
            user.Single().randomstring = "";
            tdc.SubmitChanges();
            string script = "";
            script += "<script>";
            script += "alert('Password has been reset successfully.'); window.location.href = 'login.aspx';";
            script += "</script>";
            Page.RegisterStartupScript("script", script);
            //Response.Redirect("Login.aspx");
        }
        else
        {
            lblmsg.Visible = true;
        }
    }

    protected void btnBack_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("Login.aspx");
    }
    
}